package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Coursereview;
import com.tianyi.sfzy1.service.CoursereviewService;
import com.tianyi.sfzy1.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/coursereview")
public class CoursereviewController {

    @Autowired
    private CoursereviewService coursereviewService;
    /**
     * 由课程id查询所有评价
     */
    @GetMapping
    public R findAll(int courseId){
        List<Coursereview> list=coursereviewService.findAll(courseId);
        return R.ok(list);
    }

    /**
     * 添加新评价
     */
    @PostMapping
    public R insert(String content,int stars,int memberId,int courseId){
        int i=coursereviewService.insert(content,stars,memberId,courseId);
        if (i>0){
            return R.ok(null);
        }else {
            return R.fail("添加失败");
        }
    }
}
